<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/9/5
 * Time: 9:12
 */
namespace app\service\view;

use app\common\BaseResult;
use app\common\enum\ErrorCodeEnum;
use app\common\enum\MessageEnum;
use app\facade\model\Goods;
use think\Console;
use think\facade\Request;

class GoodsService
{
    /** 列表 */
    public function getAll(array $where, string $field = "*", array $order){
        $res = Goods::all($where, $field, $order);
        return $res;
    }

    /** 详情 */
    public function getRow(array $where, string $field = "*"){
        $res = Goods::getRowInfo($where, $field);
        return $res;
    }

    /**
     * 创建
     */
    public function createRow($params){
        // $user = MemberFacade::memberInfo();
        $data = [
            "category_id" => $params['category_id'],
            "grade_id" => $params['grade_id'],
            "item_id" => $params['custom'] === true ? '' : $params['item_id'],
            "volume" => $params['volume'],
            "custom" => $params['custom'],
            "interval_time" => $params['interval_time'],
            "text" => $params['custom'] ? $params['text'] ?? '' : '',
            "create_date" => date('Y-m-d H:i:s', time())
        ];
        $res = Goods::createRow($data);
        return BaseResult::go([ 'error' => ErrorCodeEnum::SUCCESS, 'message' => '创建成功']);
    }

    /**
     * 更新藏馆
     */
    public function updateRow($params){
        $where = [
            "goods_id" => $params['id']
        ];
        $data = [
            "category_id" => $params['category_id'],
            "grade_id" => $params['grade_id'],
            "item_id" => $params['custom'] === true ? '' : $params['item_id'],
            "volume" => $params['volume'],
            "custom" => $params['custom'],
            "interval_time" => $params['interval_time'],
            "text" => $params['custom'] ? $params['text'] ?? '' : '',
        ];
        $res = Goods::updateRow($data, $where);
        return BaseResult::go([ 'error' => ErrorCodeEnum::SUCCESS, 'message' => '修改成功']);
    }
    
}